package br.com.j7.jdesk.persistence.entity;

import java.io.Serializable;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Version;


@Entity
@NamedQueries({ @NamedQuery(name="pages", query="From Pages p"),
				@NamedQuery(name="pageByCdPage", query="From Pages p where p.cdPage = ?1"),
				@NamedQuery(name="pageByUserGroup", query="Select p From Pages p INNER JOIN FETCH p.usersGroupsPages ugp WHERE ugp.userGroup = ?1")})
public class Pages implements Serializable{

	private static final long serialVersionUID = 1L;
	
	@Id
	@GeneratedValue(strategy=GenerationType.IDENTITY)
	private Integer idPage;
	private String cdPage;
	private String dsPathPage;
	
	@OneToMany(mappedBy="page", cascade=CascadeType.MERGE)
	private List<UsersGroupsPages> usersGroupsPages;
	
	
	@Version
	private Integer nrVersion;
	
	public Pages() {	
	}
	
	public Pages(Integer idPage, String cdPage, String dsPathPage) {
		super();
		this.idPage = idPage;
		this.cdPage = cdPage;
		this.dsPathPage = dsPathPage;
	}


	public Integer getIdPage() {
		return idPage;
	}

	public void setIdPage(Integer idPage) {
		this.idPage = idPage;
	}

	public String getCdPage() {
		return cdPage;
	}

	public void setCdPage(String cdPage) {
		this.cdPage = cdPage;
	}

	public String getDsPathPage() {
		return dsPathPage;
	}

	public void setDsPathPage(String dsPathPage) {
		this.dsPathPage = dsPathPage;
	}
	
	public List<UsersGroupsPages> getUsersGroupsPages() {
		return usersGroupsPages;
	}
	
	public void setUsersGroupsPages(List<UsersGroupsPages> usersGroupsPages) {
		this.usersGroupsPages = usersGroupsPages;
	}
	
	public Integer getNrVersion() {
		return nrVersion;
	}
	
	public void setNrVersion(Integer nrVersion) {
		this.nrVersion = nrVersion;
	}
	
	@Override
	public int hashCode() {
		return idPage;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Pages other = (Pages) obj;
		if (idPage == null) {
			if (other.idPage != null)
				return false;
		} else if (!idPage.equals(other.idPage))
			return false;
		return true;
	}

	@Override
	public String toString() {
		return cdPage;
	}
	
	

}
